<template>
  <span @click="handleRedo">
    <RedoOutlined :spin="loading" />
  </span>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { RedoOutlined } from '@ant-design/icons-vue';
  import { useMessage } from '/@/hooks/web/useMessage';

  export default defineComponent({
    name: 'RefreshButton',
    components: { RedoOutlined },

    setup() {
      const loading = ref(false);
      const { createMessage } = useMessage();

      async function handleRedo() {
        if (loading.value) return;

        try {
          loading.value = true;
          console.log('RefreshButton: 开始刷新页面 - 使用浏览器原生刷新');
          
          // 使用浏览器原生的刷新方法，与浏览器刷新按钮功能一致
          window.location.reload();
          
          // 注意：reload 之后的代码不会执行，因为页面已经刷新
        } catch (error) {
          console.error('RefreshButton: 页面刷新失败', error);
          createMessage.error('页面刷新失败');
          loading.value = false;
        }
      }
      return { handleRedo, loading };
    },
  });
</script>
